*
* Purpose: prepare a school-level NABC-based SES index for each year
*

forvalues year = 2008/2012 {
	use omid ses tipus using "${nabc_`year'}", clear
	
	bys omid: egen ses_mean = mean(ses)
	gen ses_resid = ses - ses_mean
	
	qui reg ses i.omid
	di e(r2)

	collapse (mean) ses (count) tipus, by(omid)
	gen year = `year'

	save "${dir_data}\ses`year'.dta", replace
}

use "${dir_data}\ses2008.dta", clear
forvalues year = 2009/2012 {
	append using "${dir_data}\ses`year'.dta"
}

qui reg ses i.omid
display e(r2)
collapse ses, by(omid)

save "${ses_2008_2012}", replace

forvalues year = 2008/2012 {
	erase "${dir_data}\ses`year'.dta"
}
